package com.felix.ocoupon.converter;

import com.felix.ocoupon.constant.OcouponCategory;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

/**
 * @author hsufelix
 * @email hsufelix@yeah.net
 * @Date 2020/11/12
 * OcouponCategoryConverter
 * 枚举转换器
 */
@Converter
public class OcouponCategoryConverter implements
        AttributeConverter<OcouponCategory, String> {

    @Override
    public String convertToDatabaseColumn(OcouponCategory ocouponCategory) {
        return ocouponCategory.getCode();
    }

    @Override
    public OcouponCategory convertToEntityAttribute(String code) {
        return OcouponCategory.of(code);
    }
}
